package mianshi.proxy.jdk;

import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class ProxyDemo {

    public static void main(String[] args) {
//        System.out.println(payment.doPay("mic"));

        JDKProxy proxy = new JDKProxy();
        IPayment payment = (IPayment)proxy.bind(new WechatPayment());
        System.out.println(payment.doPay("测试"));

        byte[] classFile = ProxyGenerator.generateProxyClass("$Proxy0", WechatPayment.class.getInterfaces());
        String path = "PaymentProxy.class";
        try(FileOutputStream fos = new FileOutputStream(path)) {
            fos.write(classFile);
            fos.flush();
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

}
